/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.msk.wlhy.service;

import com.google.common.collect.Lists;
import com.msk.common.exception.GlobalException;
import com.msk.common.utils.HtAssert;
import com.msk.common.utils.StringUtils;
import com.msk.sys.domain.Role;
import com.msk.sys.domain.User;
import com.msk.sys.mapper.UserDao;
import com.msk.sys.service.CrudService;
import com.msk.sys.service.SystemService;
import com.msk.sys.utils.SiteParamUtil;
import com.msk.wlhy.domain.HtCarFiles;
import com.msk.wlhy.domain.HtDriverFile;
import com.msk.wlhy.mapper.HtCarFilesDao;
import com.msk.wlhy.mapper.HtDriverFileDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>[]</p>
 * <p>作者：zkp</p>
 * <p>邮箱：zkp@xiangyou.com</p>
 * <p>创建时间： 2018-06-14 </p>
 * <p>类说明：驾驶员档案Service </p>
 * <p>修改记录：</p>
 */
@Service
@Transactional(readOnly = true)
public class HtDriverFileService extends CrudService<HtDriverFileDao, HtDriverFile> {
	@Autowired
	private SystemService systemService;

	@Autowired
	private UserDao userDao;

	@Autowired
	private HtCarFilesDao htCarFilesDao;

	public HtDriverFile get(String id) {
		return super.get(id);
	}

	public HtDriverFile getDriverByUser(String id) {
		return dao.getDriverByUser(id);
	}

	public List<HtDriverFile> findList(HtDriverFile htDriverFile) {
		return super.findList(htDriverFile);
	}
	
	public Map<String,Object> getDriverDetails(String userId){
		return dao.getDriverDetails(userId);
	}


	@Transactional(readOnly = false)
	public void save(HtDriverFile htDriverFile) {
		User user = systemService.getUser(htDriverFile.getUser() == null ? "" : htDriverFile.getUser().getId());
		// 获取企业用户单位和企业管理员角色
		//Office office = OfficeUtils.getOfficeByCode("xiangyou_reg_dept");
		Role r = systemService.getRoleByEnname("driver");
		List<Role> roleList= null;
		roleList = Lists.newArrayList();
		if(user == null){
			user = new User();
			if(htDriverFile.getUser()!=null && StringUtils.isNotBlank(htDriverFile.getUser().getLoginName())){
				htDriverFile.setPhone(htDriverFile.getUser().getMobile());
				user.setPhone(htDriverFile.getPhone());
				user.setNo(htDriverFile.getPhone());
				user.setMobile(htDriverFile.getPhone());
				user.setLoginName(htDriverFile.getUser().getLoginName());
				user.setPassword(SystemService.entryptPassword(htDriverFile.getUser().getPassword()));
			}else{
				user.setPhone(htDriverFile.getPhone());
				user.setNo(htDriverFile.getPhone());
				user.setMobile(htDriverFile.getPhone());
				user.setLoginName(htDriverFile.getPhone());
				//如果用户不存在则默认密码为123456
				user.setPassword(SystemService.entryptPassword("123456"));
			}

			// 是否允许登录
			user.setLoginFlag("y");
			// 注册人员
			user.setUserType("1");
			user.setUserIdentity("1");
			// 修正引用赋值问题，不知道为何，Company和Office引用的一个实例地址，修改了一个，另外一个跟着修改。
			/*User currentUser = UserUtils.getUser();//当前登录人
			if(currentUser != null){*/
			//String companyId =currentUser.getCompany().getId();
			user.setCompany(htDriverFile.getCompany());
			user.setOffice(htDriverFile.getOffice());

			roleList.add(r);
			user.setRoleList(roleList);
		}else{
			//没事用户名变更后需要清空以前用户名对应的用户缓存
			user.setOldLoginName(user.getLoginName());
			if(htDriverFile.getUser()!=null && StringUtils.isNotBlank(htDriverFile.getUser().getLoginName())){
				user.setLoginName(htDriverFile.getUser().getLoginName());
			}else{
				user.setLoginName(htDriverFile.getPhone());
			}
			user.setCompany(htDriverFile.getCompany());
			user.setOffice(htDriverFile.getOffice());
			user.setRoleList(user.getRoleList());
		}

		user.setName(htDriverFile.getName()==null?"":htDriverFile.getName());
		try{
			systemService.saveNewUser(user);
			htDriverFile.setUser(user);
		}catch(GlobalException e){
			System.out.println(e.getMessage());
		}
		if(htDriverFile.getIsPassCheck() == null){
			htDriverFile.setIsPassCheck("0");
		}
		super.save(htDriverFile);
	}

	@Transactional(readOnly = false)
	public void updateStatus(HtDriverFile htDriverFile) {
		htDriverFile.preUpdate();
		dao.updateStatus(htDriverFile);
	}

	@Transactional(readOnly = false)
	public void updateStatusNew(HtDriverFile htDriverFile) {
		dao.updateStatus(htDriverFile);
		userDao.updateNameByUserId(htDriverFile.getUser().getId(),htDriverFile.getName());
		String carId = htDriverFile.getCarId();
		if (StringUtils.isNotBlank(carId)) {
			HtCarFiles htCarFiles = htCarFilesDao.get(carId);
			htCarFiles.setIsPassCheck("1"); //审核通过司机的时候同时审核通过车辆
			this.saveCar(htCarFiles);
		}
	}

	@Transactional(readOnly = false)
	public void saveMobile(HtDriverFile htDriverFile) {
		super.save(htDriverFile);
	}
	@Transactional(readOnly = false)
	public void delete(HtDriverFile htDriverFile) {
	/*	HtCarFiles htCarFiles = new HtCarFiles();
		htCarFiles.setPhone(htDriverFile.getPhone());
		htCarFiles = htCarFilesService.getCarFilesByPhone(htCarFiles);
		if(htCarFiles != null){
			htCarFilesService.delete(htCarFiles);
		}*/
		//删除对应的用户
		User user = systemService.getUser(htDriverFile.getUser().getId());
		systemService.deleteUser(user);
		super.delete(htDriverFile);
	}

	@Transactional(readOnly = false)
	public int deleteIds(String[] ids) {
		int result = 0;
		for (String id : ids) {
			HtDriverFile htDriverFile = this.get(id);
			User user = systemService.getUser(htDriverFile.getUser().getId());
			systemService.deleteUser(user);
			super.delete(htDriverFile);
			result ++;
		}
		return result;
	}
	/**
	 * 根据手机号查找驾驶员信息，手机号也就是系统登陆名
	 * @param phone
	 * @return HtDriverFile
	 * @throws
	 */
	public HtDriverFile getHtDriverFileByPhone(String phone) {
		return dao.getHtDriverFileByPhone(phone);
	}

	//
	/**
	 * 根据身份证号码查找驾驶员信息
	 * @param idNumber
	 * @return HtDriverFile
	 * @throws
	 */
	public HtDriverFile getHtDriverFileByIdNumber(String idNumber) {
		return dao.getHtDriverFileByIdNumber(idNumber);
	}

	public HtDriverFile getHtDriverFileByUserName(String userName) {
		return dao.getHtDriverFileByLonginName(userName);
	}
	/**
	 * 更新用户的openId值
	 * @param
	 * @return List<M2mLoginUserDTO>
	 * @throws
	 */
	@Transactional(readOnly = false)
	public void updateM2mReguserOpenId(HtDriverFile htDriverFile) throws Exception {
		String openid = htDriverFile.getOpenId();
		// 根据用户ID查询出该注册用户信息
		// 将open设置为空去查询数据
		htDriverFile.setOpenId(null);
		List<HtDriverFile> htDriverFileList = findList(htDriverFile);
		HtAssert.notEmpty(htDriverFileList, "您的帐号登录发生异常，请联系系统管理员");
		HtAssert.outOfSize(htDriverFileList, 1, "您的帐号登录发生异常，请联系系统管理员");
		HtDriverFile htDriverFileUpdate = htDriverFileList.get(0);
		htDriverFileUpdate.setOpenId(openid);
		super.save(htDriverFileUpdate);
	}

	/**
	 * 修改用户密码
	 * @param
	 * @return List<M2mLoginUserDTO>
	 * @throws
	 */
	@Transactional(readOnly = false)
	public void modifyPassword(Map<String, Object> params) throws Exception {
		String oldPassword = ObjectUtils.getDisplayString(params.get("oldPassword")).trim();
		String newPassword = ObjectUtils.getDisplayString(params.get("newPassword")).trim();
		String confirmPassword = ObjectUtils.getDisplayString(params.get("confirmPassword")).trim();

		HtAssert.hasLength(oldPassword, "旧密码不允许为空");
		HtAssert.isNull(newPassword, "新密码不允许为空");
		if (!newPassword.equals(confirmPassword)) {
			throw new GlobalException("新密码和确认密码不一致");
		}
//		User user = UserUtils.getUser();
//		if (SystemService.validatePassword(oldPassword, UserUtils.getUser().getPassword())) {
//			systemService.updatePasswordById(user.getId(), user.getLoginName(), newPassword);
//		} else {
//			throw new GlobalException("修改密码失败，旧密码错误");
//		}
	}
	/**
	 * 解除绑定的微信号
	 * @param
	 * @param
	 * @return
	 * @throws Exception
	 */
	@Transactional(readOnly = false)
	public void removeOpenId(HtDriverFile htDriverFile) throws Exception {
		List<HtDriverFile> list = findList(htDriverFile);
		if (!CollectionUtils.isEmpty(list)) {
			for (int i = 0; i < list.size(); i++) {
				HtDriverFile htDriverFileTemp = list.get(i);
				String[] openids = htDriverFileTemp.getOpenId().split(",");
				List<String> openids1 = new ArrayList<String>();
				for (int j = 0; j < openids.length; j++) {
					String openid  =  openids[j];
					if(!openid.equals(htDriverFile.getOpenId())){
						openids1.add(openid);
					}
				}

				StringBuffer sb = new StringBuffer();

				for (int j = 0; j < openids1.size(); j++) {
					if(j < openids1.size() - 1){
						sb.append(openids1.get(j) +",");
					}else{
						sb.append(openids1.get(j));
					}
				}
				htDriverFileTemp.setOpenId(sb.toString());
				super.save(htDriverFileTemp);
			}
		}
	}
	/**
	 * 根据运输单id获取对应的司机信息
	 * @param htDriverFile
	 * @return List<HtDriverFile>
	 * @throws
	 */
	public List<HtDriverFile> findListByTransportListId(HtDriverFile htDriverFile) {
		return dao.findListByTransportListId(htDriverFile);
	}


	/**
	 * 根据司机id获取绑定车辆的数量
	 * @description getCarCountByDriverId
	 * @date 2018-7-17
	 * @author chuming
	 * @param id
	 * @return
	 */
	public Long getCarCountByDriverId(String id){
		return dao.getCarCountByDriverId(id);
	}

	/**
	 * @description getDriverByUserId
	 * @date 2018-8-2
	 * @author chuming
	 * @param userid
	 * @return
	 */
	public HtDriverFile getDriverByUserId(String userid) {
		return dao.getDriverByUserId(userid);
	}

	/**
	 * @description saveOnly
	 * @date 2018-8-6
	 * @author chuming
	 * @param driverFile
	 */
	@Transactional(readOnly = false)
	public void saveOnly(HtDriverFile driverFile) {
		super.save(driverFile);
	}

	public Long findCount(HtDriverFile htDriverFile){
		return dao.findCount(htDriverFile);
	}
	
	/**
	 * @author llh
	 * @date 2023/6/6
	 * @return void
	 * @description 小程序保存司机      
	 */
	@Transactional(readOnly = false)
	public void saveAuthDriver(HtDriverFile htDriverFile){
		htDriverFile.setAttstr01("1");
		htDriverFile.setAttstr02(htDriverFile.getCarNumber());
		super.save(htDriverFile);
		String carId = htDriverFile.getCarId();
		HtCarFiles carFiles = new HtCarFiles();
		carFiles.setDriverId(htDriverFile.getId());
		HtCarFiles htCarFiles = htCarFilesDao.getCarByDriverId(carFiles);
		htCarFiles.preUpdate();
		htCarFiles.setIsPassCheck("3");
		htCarFiles.setCarType(htDriverFile.getCarType());
		htCarFiles.setCarNumber(htDriverFile.getCarNumber());
		htCarFiles.setCarLoad(htDriverFile.getCarLoad());
		htCarFiles.setTransportNumber(htDriverFile.getTransportNumber());
		htCarFiles.setTransportPic(htDriverFile.getTransportPic());
		htCarFiles.setDrivingLicensePic(htDriverFile.getDrivingLicensePic());
		htCarFiles.setDrivingLicensePicCopy(htDriverFile.getDrivingLicensePicCopy());
		htCarFiles.setDriverId(htDriverFile.getId());
		htCarFiles.setMasterDriverUser(htDriverFile);
		htCarFiles.setCarWeightType(htDriverFile.getCarWeightType());
		htCarFiles.setCarWeight(htDriverFile.getCarWeight());
		htCarFiles.setCarLength(htDriverFile.getCarLength());
		htCarFiles.setColor(htDriverFile.getCarColor());
		htCarFiles.setVehicleEnergyType(htDriverFile.getVehicleEnergyType());
		htCarFiles.setRoadTransportBizLicenseNo(htDriverFile.getRoadTransportBizLicenseNo());
		htCarFiles.setIssuingOrganizations(htDriverFile.getIssuingOrganizations());
		htCarFiles.setPeriodStartDate(htDriverFile.getPeriodStartDate());
		htCarFiles.setPeriodEndDate(htDriverFile.getPeriodEndDate());
		htCarFiles.setIssueDate(htDriverFile.getIssueDate());
		htCarFiles.setRegisterDate(htDriverFile.getRegisterDate());
		htCarFiles.setVehicleAreaCode(htDriverFile.getVehicleAreaCode());
		htCarFiles.setAllUser(htDriverFile.getAllUser());
		htCarFiles.setUseCharacter(htDriverFile.getUseCharacter());
		htCarFiles.setVin(htDriverFile.getVin());
		htCarFiles.setState("1");
		//设置默认值
		if(StringUtils.isBlank(htCarFiles.getVehicleOwnership())){
			htCarFiles.setVehicleOwnership("2");
		}

		if (StringUtils.isEmpty(htCarFiles.getId())) {
			htCarFiles.setStatus("1");// 新增车辆默认为可用
		}
		if(StringUtils.isBlank(htCarFiles.getCarType())){
			if("3".equals(htDriverFile.getIsPassCheck())){
				htCarFiles.setCarType("");
			}else{
				htCarFiles.setCarType("H01");
			}
		}

		if(StringUtils.isBlank(htCarFiles.getLicenseType())){
			htCarFiles.setLicenseType("01");
		}

		if(StringUtils.isBlank(htCarFiles.getCarWeightType())){
			htCarFiles.setCarWeightType("0");
		}
		if (StringUtils.isEmpty(htCarFiles.getId())) {
			htCarFiles.setStatus("1");// 新增车辆默认为可用
			if (htDriverFile.getOffice() != null) {
				htCarFiles.setOffice(htDriverFile.getOffice());
				htCarFiles.setCompany(htDriverFile.getOffice().getParent());
			}
		}
		this.saveCar(htCarFiles);
	}

	/**
	 * 司机端最新认证
	 * @param htDriverFile
	 */
	@Transactional(readOnly = false)
	public void saveNewDriver(HtDriverFile htDriverFile) {
		htDriverFile.setAttstr01("1");
		htDriverFile.setAttstr02(htDriverFile.getCarNumber());
		super.save(htDriverFile);
		String carId = htDriverFile.getCarId();
		HtCarFiles htCarFiles = new HtCarFiles();
		if (StringUtils.isNotBlank(carId)) {
			htCarFiles = htCarFilesDao.get(carId);
		}
		if(StringUtils.isNotBlank(carId)){
			htCarFiles.preUpdate();
		}else{
			htCarFiles.preInsert();
		}
		if("3".equals(htDriverFile.getIsPassCheck())){
			htCarFiles.setIsPassCheck("3");
		}else{
			htCarFiles.setIsPassCheck("1");
		}
		htCarFiles.setId(carId);
		htCarFiles.setCarType(htDriverFile.getCarType());
		htCarFiles.setCarNumber(htDriverFile.getCarNumber());
		htCarFiles.setCarLoad(htDriverFile.getCarLoad());
		htCarFiles.setTransportNumber(htDriverFile.getTransportNumber());
		htCarFiles.setTransportPic(htDriverFile.getTransportPic());
		htCarFiles.setDrivingLicensePic(htDriverFile.getDrivingLicensePic());
		htCarFiles.setDrivingLicensePicCopy(htDriverFile.getDrivingLicensePicCopy());
		htCarFiles.setDriverId(htDriverFile.getId());
		htCarFiles.setMasterDriverUser(htDriverFile);
		htCarFiles.setCarWeightType(htDriverFile.getCarWeightType());
		htCarFiles.setCarWeight(htDriverFile.getCarWeight());
		htCarFiles.setCarLength(htDriverFile.getCarLength());
		htCarFiles.setColor(htDriverFile.getCarColor());
		htCarFiles.setVehicleEnergyType(htDriverFile.getVehicleEnergyType());
		htCarFiles.setRoadTransportBizLicenseNo(htDriverFile.getRoadTransportBizLicenseNo());
		htCarFiles.setIssuingOrganizations(htDriverFile.getIssuingOrganizations());
		htCarFiles.setPeriodStartDate(htDriverFile.getPeriodStartDate());
		htCarFiles.setPeriodEndDate(htDriverFile.getPeriodEndDate());
		htCarFiles.setIssueDate(htDriverFile.getIssueDate());
		htCarFiles.setRegisterDate(htDriverFile.getRegisterDate());
		htCarFiles.setVehicleAreaCode(htDriverFile.getVehicleAreaCode());
		htCarFiles.setAllUser(htDriverFile.getAllUser());
		htCarFiles.setUseCharacter(htDriverFile.getUseCharacter());
		htCarFiles.setVin(htDriverFile.getVin());

		htCarFiles.setState("1");
		//设置默认值
		if(StringUtils.isBlank(htCarFiles.getVehicleOwnership())){
			htCarFiles.setVehicleOwnership("2");
		}

		if (StringUtils.isEmpty(htCarFiles.getId())) {
			htCarFiles.setStatus("1");// 新增车辆默认为可用
		}
		if(StringUtils.isBlank(htCarFiles.getCarType())){
			if("3".equals(htDriverFile.getIsPassCheck())){
				htCarFiles.setCarType("");
			}else{
				htCarFiles.setCarType("H01");
			}
		}

		if(StringUtils.isBlank(htCarFiles.getLicenseType())){
			htCarFiles.setLicenseType("01");
		}

		if(StringUtils.isBlank(htCarFiles.getCarWeightType())){
			htCarFiles.setCarWeightType("0");
		}
		if(!SiteParamUtil.isDriver()) {
			htCarFiles.setIsPassCheck("1"); //车辆已审核
		}else{
			htCarFiles.setIsPassCheck("0"); //车辆待审核
		}
		if (StringUtils.isEmpty(htCarFiles.getId())) {
			htCarFiles.setStatus("1");// 新增车辆默认为可用
			if (htDriverFile.getOffice() != null) {
				htCarFiles.setOffice(htDriverFile.getOffice());
				htCarFiles.setCompany(htDriverFile.getOffice().getParent());
			}
		}
		this.saveCar(htCarFiles);
	}

	/**
	 * 添加车辆
	 * @param htCarFiles
	 */
	public void saveCar(HtCarFiles htCarFiles) {
		if (StringUtils.isEmpty(htCarFiles.getId())){
			htCarFiles.preInsert();
			htCarFilesDao.insert(htCarFiles);
		}else{
			htCarFiles.preUpdate();
			if(htCarFilesDao.update(htCarFiles) == 0){
				throw new GlobalException("数据失效，请重新更新");
			}
		}
	}

	/**
	 * 根据司机ID获取车辆信息
	 * @param driverId
	 * @return
	 */
	public HtCarFiles findCarFilesByDriverId(String driverId) {
		HtCarFiles htCarFiles = htCarFilesDao.findCarFilesByDriverId(driverId);
		return htCarFiles;
	}

	@Transactional(readOnly = false)
	public void saveNew(HtDriverFile htDriverFile) {
		User user = systemService.getUser(htDriverFile.getUser() == null ? "" : htDriverFile.getUser().getId());
		// 获取企业用户单位和企业管理员角色
		//Office office = OfficeUtils.getOfficeByCode("xiangyou_reg_dept");
		Role r = systemService.getRoleByEnname("driver");
		List<Role> roleList= null;
		roleList = Lists.newArrayList();
		htDriverFile.setDriverStatus("0");
		if(user == null){
			user = new User();
			if(htDriverFile.getUser()!=null && StringUtils.isNotBlank(htDriverFile.getUser().getLoginName())){
				htDriverFile.setPhone(htDriverFile.getUser().getMobile());
				user.setPhone(htDriverFile.getPhone());
				user.setNo(htDriverFile.getPhone());
				user.setMobile(htDriverFile.getPhone());
				user.setLoginName(htDriverFile.getUser().getLoginName());
				user.setPassword(SystemService.entryptPassword(htDriverFile.getUser().getPassword()));
			}else{
				user.setPhone(htDriverFile.getPhone());
				user.setNo(htDriverFile.getPhone());
				user.setMobile(htDriverFile.getPhone());
				user.setLoginName(htDriverFile.getPhone());
				//如果用户不存在则默认密码为abcd1234
				user.setPassword(SystemService.entryptPassword("abcd1234"));
			}

			// 是否允许登录
			user.setLoginFlag("y");
			// 注册人员
			user.setUserType("1");
			user.setUserIdentity("1");
			// 修正引用赋值问题，不知道为何，Company和Office引用的一个实例地址，修改了一个，另外一个跟着修改。
			/*User currentUser = UserUtils.getUser();//当前登录人
			if(currentUser != null){*/
			//String companyId =currentUser.getCompany().getId();
			user.setCompany(htDriverFile.getCompany());
			user.setOffice(htDriverFile.getOffice());

			roleList.add(r);
			user.setRoleList(roleList);
		}else{
			//没事用户名变更后需要清空以前用户名对应的用户缓存
			user.setOldLoginName(user.getLoginName());
			if(htDriverFile.getUser()!=null && StringUtils.isNotBlank(htDriverFile.getUser().getLoginName())){
				user.setLoginName(htDriverFile.getUser().getLoginName());
			}else{
				user.setLoginName(htDriverFile.getPhone());
			}
			user.setCompany(htDriverFile.getCompany());
			user.setOffice(htDriverFile.getOffice());
			user.setRoleList(user.getRoleList());
		}

		user.setName(htDriverFile.getName()==null?"":htDriverFile.getName());
		try{
			systemService.saveUser(user);
			htDriverFile.setUser(user);
		}catch(GlobalException e){
			logger.error(e.getMessage());
		}
		//1.承运商保存需要审核，2.管理员添加不需要审核；
		User u = null;
		if(htDriverFile.getIsPassCheck() == null){
			if(u != null && (StringUtils.isNotBlank(u.getUserIdentity())||StringUtils.isNotBlank(u.getMainAccountId()))){
				htDriverFile.setIsPassCheck("0");
			}else{
				htDriverFile.setIsPassCheck("1");
				htDriverFile.setAuditUser(u);
			}
		}
		super.save(htDriverFile);

		String carNo = htDriverFile.getCarNumber();
		if(StringUtils.isNotBlank(carNo)){
			String carId = htDriverFile.getCarId();

			HtCarFiles htCarFiles = htCarFilesDao.findEntityByCarNumber(carNo);
			if(htCarFiles == null){
				htCarFiles = new HtCarFiles();
				htCarFiles.setId(carId);
			}
			if (StringUtils.isNotBlank(carId)) {
				htCarFiles = htCarFilesDao.get(carId);
			}

			htCarFiles.setCarNumber(htDriverFile.getCarNumber());
			htCarFiles.setCarLoad(htDriverFile.getCarLoad());
			htCarFiles.setTransportNumber(htDriverFile.getTransportNumber());
			htCarFiles.setTransportPic(htDriverFile.getTransportPic());
			htCarFiles.setDrivingLicensePic(htDriverFile.getDrivingLicensePic());
			htCarFiles.setDrivingLicensePicCopy(htDriverFile.getDrivingLicensePicCopy());
			htCarFiles.setDriverId(htDriverFile.getId());
			htCarFiles.setMasterDriverUser(htDriverFile);
			htCarFiles.setCarWeightType(htDriverFile.getCarWeightType());
			htCarFiles.setCarWeight(htDriverFile.getCarWeight());
			htCarFiles.setCarLength(htDriverFile.getCarLength());
			htCarFiles.setColor(htDriverFile.getCarColor());
            htCarFiles.setRoadTransportBizLicenseNo(htDriverFile.getRoadTransportBizLicenseNo());
			htCarFiles.setVehicleEnergyType(htDriverFile.getVehicleEnergyType());
			htCarFiles.setState("1");
			//设置默认值
			if(StringUtils.isBlank(htCarFiles.getVehicleOwnership())){
				htCarFiles.setVehicleOwnership("2");
			}

			if (StringUtils.isEmpty(htCarFiles.getId())) {
				htCarFiles.setStatus("1");// 新增车辆默认为可用
			}
			if(StringUtils.isBlank(htCarFiles.getCarType())){
				htCarFiles.setCarType("H01");
			}

			if(StringUtils.isBlank(htCarFiles.getLicenseType())){
				htCarFiles.setLicenseType("01");
			}

			if(StringUtils.isBlank(htCarFiles.getCarWeightType())){
				htCarFiles.setCarWeightType("0");
			}

			htCarFiles.setIsPassCheck("0"); //车辆待审核
			if (StringUtils.isEmpty(htCarFiles.getId())) {
				if(u != null && (StringUtils.isNotBlank(u.getUserIdentity())||StringUtils.isNotBlank(u.getMainAccountId()))){
					htCarFiles.setStatus("0");
				}else{
					htCarFiles.setStatus("1");// 新增车辆默认为可用
				}

				if (htDriverFile.getOffice() != null) {
					htCarFiles.setOffice(htDriverFile.getOffice());
					htCarFiles.setCompany(htDriverFile.getOffice().getParent());
				}
			}
			this.saveCar(htCarFiles);
		}
	}

	public List<Map<String,Object>> findPage1(HtDriverFile htDriverFile) {
		return dao.findListForTransportList(htDriverFile);
	}

	@Transactional(readOnly = false)
	public void updatedriverStatus(HtDriverFile htDriverFile){
		dao.updatedriverStatus(htDriverFile);
	}
    @Transactional(readOnly = false)
    public void saveBackend(HtDriverFile htDriverFile) {
        User user = systemService.getUser(htDriverFile.getUser() == null ? "" : htDriverFile.getUser().getId());
        // 获取企业用户单位和企业管理员角色
        //Office office = OfficeUtils.getOfficeByCode("xiangyou_reg_dept");
        Role r = systemService.getRoleByEnname("driver");
        List<Role> roleList= null;
        roleList = Lists.newArrayList();
        if(user == null){
            user = new User();
            if(htDriverFile.getUser()!=null && StringUtils.isNotBlank(htDriverFile.getUser().getLoginName())){
                htDriverFile.setPhone(htDriverFile.getUser().getMobile());
                user.setPhone(htDriverFile.getPhone());
                user.setNo(htDriverFile.getPhone());
                user.setMobile(htDriverFile.getPhone());
                user.setLoginName(htDriverFile.getUser().getLoginName());
                user.setPassword(SystemService.entryptPassword(htDriverFile.getUser().getPassword()));
            }else{
                user.setPhone(htDriverFile.getPhone());
                user.setNo(htDriverFile.getPhone());
                user.setMobile(htDriverFile.getPhone());
                user.setLoginName(htDriverFile.getPhone());
                //如果用户不存在则默认密码为Abcd1234
                user.setPassword(SystemService.entryptPassword("Abcd1234"));
            }

            // 是否允许登录
            user.setLoginFlag("y");
            // 注册人员
            user.setUserType("1");
            user.setUserIdentity("1");
            // 修正引用赋值问题，不知道为何，Company和Office引用的一个实例地址，修改了一个，另外一个跟着修改。
			/*User currentUser = UserUtils.getUser();//当前登录人
			if(currentUser != null){*/
            //String companyId =currentUser.getCompany().getId();
            user.setCompany(htDriverFile.getCompany());
            user.setOffice(htDriverFile.getOffice());

            roleList.add(r);
            user.setRoleList(roleList);
        }else{
            //没事用户名变更后需要清空以前用户名对应的用户缓存
            user.setOldLoginName(user.getLoginName());
            if(htDriverFile.getUser()!=null && StringUtils.isNotBlank(htDriverFile.getUser().getLoginName())){
                user.setLoginName(htDriverFile.getUser().getLoginName());
            }else{
                user.setLoginName(htDriverFile.getPhone());
            }
            user.setCompany(htDriverFile.getCompany());
            user.setOffice(htDriverFile.getOffice());
            user.setRoleList(user.getRoleList());
        }

        user.setName(htDriverFile.getName()==null?"":htDriverFile.getName());
        try{
            systemService.saveUser(user);
            htDriverFile.setUser(user);
        }catch(GlobalException e){
            System.out.println(e.getMessage());
        }
        User u = null;
        if(StringUtils.isBlank(htDriverFile.getIsPassCheck())){
            if(u != null && (StringUtils.isNotBlank(u.getUserIdentity())||StringUtils.isNotBlank(u.getMainAccountId()))){
                htDriverFile.setIsPassCheck("0");
            }else{
                htDriverFile.setIsPassCheck("1");
                htDriverFile.setAuditUser(u);
            }
        }
        super.save(htDriverFile);
    }

	public static void main(String[] args) {
		String phone = "13474137611";
		System.out.println(phone.substring(5));

		String str = "7.525*2.495*3.41";
		System.out.println(str.split("\\*")[0]);
	}
}